package com.yuandian.management.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.po.ConfMpServiceParams;
import com.yuandian.api.management.vo.OptionVo;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.api.management.entity.ConfMpService;
import com.yuandian.management.service.ConfMpServiceService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * 中台监控-服务配置表-Controller
 * @author zfsn
 * @date 2023-4-18
 */
@Api(tags = "中台监控-服务配置")
@RestController
@RequestMapping("/mp/service")
public class ConfMpServiceController {

	@Autowired
	private ConfMpServiceService confMpServiceService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键查询", notes = "通过主键查询服务配置，支持批量查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "主键数组", paramType = "path", required = true, dataType = "String", dataTypeClass = String.class)
	})
	@GetMapping("/queryByIds/{ids}")
	// @PreAuthorize("@pms.hasPermission('conf_mp_service_view')")
	public R<List<ConfMpService>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confMpServiceService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param params 中台监控-服务配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "current", value = "当前页", paramType = "body", required = true, dataType = "Long", dataTypeClass = Long.class),
			@ApiImplicitParam(name = "size", value = "每页条数", paramType = "body", required = true, dataType = "Long", dataTypeClass = Long.class),
			@ApiImplicitParam(name = "orders", value = "排序方式", paramType = "body", required = false, dataType = "OrderItem", dataTypeClass = OrderItem.class, allowMultiple = true),
			@ApiImplicitParam(name = "abilityId", value = "所属能力id", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "serviceCode", value = "服务编码", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "serviceName", value = "服务名称", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class)
	})
	@PostMapping("/page")
	// @PreAuthorize("@pms.hasPermission('conf_mp_service_view')")
	public R<Page<ConfMpService>> page(@ApiIgnore @RequestBody ConfMpServiceParams params) {
		return confMpServiceService.page(params);
	}

	/**
	 * 新增数据
	 * @param params 中台监控-服务配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增服务", notes = "新增服务配置")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "abilityId", value = "所属能力id", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "middlePlatformId", value = "所属中台id", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "invocationMode", value = "服务调用模式编码", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "serviceCode", value = "服务编码", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "serviceName", value = "服务名称", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "isFrequentAccess", value = "是否频繁访问", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "interruptTimeThreshold", value = "中断耗时阈值", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "fastResUplimitThreshold", value = "快速响应上限阈值", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "normalResUplimitThreshold", value = "正常响应上限阈值", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "slowResUplimitThreshold", value = "缓慢响应上限阈值", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "remarks", value = "描述", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class)
	})
	@PostMapping("/save")
	// @PreAuthorize("@pms.hasPermission('conf_mp_service_add')")
	public R<Boolean> save(@ApiIgnore @RequestBody ConfMpServiceParams params) {
		return confMpServiceService.saveWrap(params);
	}

	/**
	 * 通过主键更新数据
	 * @param params 中台监控-服务配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键更新", notes = "通过主键更新服务配置")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "主键", paramType = "body", required = true, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "abilityId", value = "所属能力id", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "middlePlatformId", value = "所属中台id", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "invocationMode", value = "服务调用模式编码", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "serviceCode", value = "服务编码", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "serviceName", value = "服务名称", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class),
			@ApiImplicitParam(name = "isFrequentAccess", value = "是否频繁访问", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "interruptTimeThreshold", value = "中断耗时阈值", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "fastResUplimitThreshold", value = "快速响应上限阈值", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "normalResUplimitThreshold", value = "正常响应上限阈值", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "slowResUplimitThreshold", value = "缓慢响应上限阈值", paramType = "body", required = false, dataType = "Integer", dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "remarks", value = "描述", paramType = "body", required = false, dataType = "String", dataTypeClass = String.class)
	})
	@PutMapping("/updateById")
	// @PreAuthorize("@pms.hasPermission('conf_mp_service_update')")
	public R<Boolean> updateById(@ApiIgnore @RequestBody ConfMpServiceParams params) {
		return confMpServiceService.updateByIdWrap(params);
	}

	/**
	 * 通过主键删除数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键删除", notes = "通过主键删除服务配置，支持批量删除")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "主键数组", paramType = "path", required = true, dataType = "String", dataTypeClass = String.class)
	})
	@DeleteMapping("/removeByIds/{ids}")
	// @PreAuthorize("@pms.hasPermission('conf_mp_service_delete')")
	public R<Boolean> removeByIds(@PathVariable("ids") List<Integer> idList) {
		return confMpServiceService.removeByIdsWrap(idList);
	}

	/**
	 * 查询服务选项
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "查询服务选项", notes = "查询服务选项")
	@GetMapping("/option/{abilityId}")
	public R<List<OptionVo>> option(@PathVariable("abilityId") Integer abilityId) {
		return confMpServiceService.option(abilityId);
	}


	/**
	 * 通过主键更新数据
	 * @param params 中台监控-服务配置请求参数
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "主键更新", notes = "通过主键更新服务配置")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", 					value = "主键", 		paramType = "body", required = true, 	dataType = "Integer", 		dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "majorDimension", 		value = "主量纲", 	paramType = "body", required = true, 	dataType = "String", 		dataTypeClass = String.class),
			@ApiImplicitParam(name = "subDimensionList", 	value = "副量纲", 	paramType = "body", required = false, 	dataType = "List<String>",  dataTypeClass = List.class),
	})
	@PutMapping("/updateDimensionById")
	// @PreAuthorize("@pms.hasPermission('conf_mp_service_update')")
	public R<Object> updateDimensionById(@ApiIgnore @RequestBody ConfMpService params) {
		return confMpServiceService.updateDimensionById(params);
	}


	/**
	 * 查询主量纲下拉框
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "查询主量纲下拉框", notes = "查询主量纲下拉框")
	@GetMapping("/dimensionOption")
	public R<List<OptionVo>> majorDimensionOption() {
		return confMpServiceService.majorDimensionOption();
	}


	/**
	 * 查询副量纲下拉框
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "查询副量纲下拉框", notes = "查询副量纲下拉框")
	@GetMapping("/subDimensionOption")
	public R<List<OptionVo>> subDimensionOption() {
		return confMpServiceService.subDimensionOption();
	}

}